package com.xxh.test;

import com.rabbitmq.client.*;
import com.xxh.utils.MqUtils;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 消息的消费者
 */
public class Consumer {
    @Test
    public void test() throws IOException {

            Connection connection = MqUtils.getConnection();
            Channel channel = connection.createChannel();
            //绑定
            channel.queueDeclare("hello",false,false,false,null);
            //消费消息
            /**
             * 1 消费那个队列消息
             * 2 开启消息自都确认
             * 3 回调接口
             */
            channel.basicConsume("hello",true,new DefaultConsumer(channel){
                @Override
                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                    System.out.println("i got your message :"+new String(body));
                }
            });

    }
}
